var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("GlobalParams"),
    n = e("AssetsManager"),
    i = e("AudioManager"),
    r = e("ModuleUI"),
    s = e("CommonHelper"),
    l = e("Game"),
    _ = e("nameCfg"),
    c = e("sdkConfig"),
    d = e("Toast"),
    h = cc._decorator,
    u = h.ccclass,
    p = h.property,
    m = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.count_down_time = null),
                (t.match_tip_label = null),
                (t.red_frame_node = null),
                (t.blue_frame_node = null),
                (t.count_down = 0),
                (t.random_name = []),
                (t.random_hero = []),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this),
                    (a.GlobalParams.MathcTimeInfo.open = !1),
                    (a.GlobalParams.MathcTimeInfo.name = ""),
                    (this.count_down = 1),
                    (this.random_name = []),
                    this.getMatchPlayer(),
                    this.showMatchAnime(),
                    i.default.getInstance().playFx("begin_game");
            }),
            (t.prototype.OnClick = function (t) {
                switch ((e.prototype.OnClick.call(this, t), t.node.name)) {
                    case "back_btn":
                        if (a.GlobalParams.PlayGuideMode) return void d.default.showNewToast("引导中请勿操作");
                        (a.GlobalParams.MathcTimeInfo.open = !0), (a.GlobalParams.TryNewHero = !1), this.node.destroy();
                }
            }),
            (t.prototype.getMatchPlayer = function () {
                a.GlobalParams.MatchGamePlayer = [];
                var e = 0,
                    t = "" != a.GlobalParams.MathcTimeInfo.name,
                    o = 0;
                t ? (o = (e = s.default.getRandomInt(2, 9)) - 2) : (e = s.default.getRandomInt(0, 2)),
                    a.GlobalParams.PlayGuideMode && (e = 8),
                    (a.GlobalParams.MatchMyIndex = e);
                var n = a.GlobalParams.PlayerInfo.value;
                this.random_name.push(n.name);
                for (var i = 0; i < e; i++)
                    this.addAIPlayer(),
                        t &&
                        i == o &&
                        ((a.GlobalParams.MatchGamePlayer[i].name = a.GlobalParams.MathcTimeInfo.name),
                            (a.GlobalParams.MatchGamePlayer[i].head = a.GlobalParams.MathcTimeInfo.head)),
                        (this.count_down += s.default.getRandomInt(0, 2));
                a.GlobalParams.MatchGamePlayer[e] = {
                    name: n.name,
                    head: n.head,
                    role_id: 0,
                    player_skill: [1, 2],
                    dower_info: [0, 0],
                    level: 1,
                    exp_num: 0,
                    kill_info: [0, 0, 0],
                    skill_info: [0, 0, 0],
                    equip_info: [0, 0, 0, 0, 0, 0],
                    coin: 0
                };
            }),
            (t.prototype.addAIPlayer = function () {
                var e = "";
                do {
                    e =
                        c.default.platform != c.EPlatform.NET_4399
                            ? _.default.nameList[s.default.getRandomInt(0, _.default.nameList.length - 1)]
                            : "4399玩家" + s.default.getRandomInt(1e3, 9999);
                } while (-1 != this.random_name.indexOf(e));
                this.random_name.push(e);
                var t = 0;
                if (a.GlobalParams.ChangeGameMode == l.GameType.clone_mode)
                    t =
                        a.GlobalParams.GameHeroIndex[
                        s.default.getRandomInt(0, a.GlobalParams.GameHeroIndex.length - 1)
                        ];
                else
                    do {
                        t =
                            a.GlobalParams.GameHeroIndex[
                            s.default.getRandomInt(0, a.GlobalParams.GameHeroIndex.length - 1)
                            ];
                    } while (-1 != this.random_hero.indexOf(t));
                this.random_hero.push(t);
                var o = s.default.getRandomInt(0, 4),
                    n = {
                        name: e,
                        head:
                            c.default.platform != c.EPlatform.NET_4399
                                ? s.default.getRandomInt(1, 15)
                                : s.default.getRandomInt(1, 9),
                        role_id: t,
                        player_skill: [1, 2],
                        dower_info: [o, a.GlobalParams.PlayerDowerInfo.value.dower[o]],
                        level: 1,
                        exp_num: 0,
                        kill_info: [0, 0, 0],
                        skill_info: [1, 0, 0],
                        equip_info: [0, 0, 0, 0, 0, 0],
                        coin: 0
                    };
                a.GlobalParams.MatchGamePlayer.push(n);
            }),
            (t.prototype.showMatchInfo = function () {
                for (var e = this, t = 0; t < 10; t++) {
                    var o = Math.floor(t / 2),
                        i = t % 2 == 0 ? this.blue_frame_node : this.red_frame_node,
                        r = a.GlobalParams.MatchGamePlayer[t];
                    (i.children[o].children[0].active = !!r),
                        (i.children[o].children[1].getComponent(cc.Sprite).spriteFrame = r
                            ? n.default.getInstance().getHeroHeadFrame("hero_" + r.head)
                            : null);
                }
                a.GlobalParams.MatchGamePlayer.length < 10
                    ? this.scheduleOnce(function () {
                        e.addAIPlayer(), e.showMatchInfo();
                    }, s.default.getRandom(0, 2))
                    : this.scheduleOnce(function () {
                        e.unscheduleAllCallbacks(), e.uiManager.showPopup("ChooseHoreViewUI"), e.node.destroy();
                    }, 1);
            }),
            (t.prototype.showMatchAnime = function () {
                var e = this;
                (this.match_tip_label.node.active = !1),
                    (this.count_down_time.node.scale = 0.1),
                    this.scheduleOnce(function () {
                        (e.match_tip_label.node.active = !0), e.showMatchInfo(), e.countDown();
                    }, 0.3);
            }),
            (t.prototype.countDown = function () {
                var e = this;
                (this.count_down_time.string = "" + this.count_down), (this.match_tip_label.string = "正在匹配");
                for (var t = 0; t < 3; t++) t < this.count_down % 4 && (this.match_tip_label.string += "。");
                cc.tween(this.count_down_time.node)
                    .to(0.8, { scale: 1 })
                    .delay(0.2)
                    .call(function () {
                        (e.count_down_time.node.scale = 0.1), e.count_down++, e.countDown();
                    })
                    .start();
            }),
            oo([p(cc.Label)], t.prototype, "count_down_time", void 0),
            oo([p(cc.Label)], t.prototype, "match_tip_label", void 0),
            oo([p(cc.Node)], t.prototype, "red_frame_node", void 0),
            oo([p(cc.Node)], t.prototype, "blue_frame_node", void 0),
            oo([u], t)
        );
    })(r.default);
o.default = m;
